package com.heisen.base.print;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;

/**
 * @author sen
 * @description
 * @date 2023/12/18 16:16
 */
public class PrintBanner implements ApplicationListener<ApplicationReadyEvent> {




    public static final String[] BANNER = {
            "\n"+
                    "          __                 __                                                      \n" +
                    "  _______/  |______ ________/  |_      ________ __   ____  ____  ____   ______ ______\n" +
                    " /  ___/\\   __\\__  \\\\_  __ \\   __\\    /  ___/  |  \\_/ ___\\/ ___\\/ __ \\ /  ___//  ___/\n" +
                    " \\___ \\  |  |  / __ \\|  | \\/|  |      \\___ \\|  |  /\\  \\__\\  \\__\\  ___/ \\___ \\ \\___ \\ \n" +
                    "/____  > |__| (____  /__|   |__|     /____  >____/  \\___  >___  >___  >____  >____  >\n" +
                    "     \\/            \\/                     \\/            \\/    \\/    \\/     \\/     \\/ "


    };


    @Override
    public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
        Log log = LogFactory.getLog(PrintBanner.class);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PrintStream printStream = new PrintStream(baos);
        for (String s : BANNER) {
            printStream.println(s);
        }

        try {
            log.info(baos.toString("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
    }
}
